﻿using ICPFrameLib.Business;
using ICPFrameLib.Attributes;
using XHRPMIS.Common;
using EFFC.Frame.Net.Base.Common;
using EFFC.Frame.Net.Base.Data.Base;
using EFFC.Frame.Net.Module.Extend.EWRA.Attributes;
using EFFC.Frame.Net.Module.Extend.EWRA.Attributes.Validation;
using EFFC.Frame.Net.Unit.DB.Parameters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using EFFC.Extends.LinqDLR2SQL;
using EFFC.Frame.Net.Unit.DB;
using EFFC.Frame.Net.Base.Data;
using System.IO;
using EFFC.Frame.Net.Base.Constants;
using System.Text.RegularExpressions;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using System.Text;
using ICPFrameLib.Common;
using EFFC.Frame.Net.Unit.DB.Datas;

namespace XHRPMIS.Business.v1._0
{
    public partial class MetaDynamicForm
{
    #region OpenAPI
    [EWRARouteDesc("自动编码栏位自动生成code")]
    [EWRARoute("post", "/md_form/autocode/{id}/{column_name}")]
    [EWRAAddInput("id", "string", "元数据表的uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("column_name", "string", "指定栏位的名称", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("data", "object", "当前行或form数据", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, false)]
    [EWRAOutputDesc("返回结果", @"如果是授权无效的情况下，返回400错，其它情况的返回结果集（状态为200）如下：{
code:'success-成功，failed-失败',
msg:'提示信息',
data:'生成的code'
}")]
    object GetAutoCode(string id, string column_name)
    {
        FrameDLRObject data = FrameDLRObject.CreateInstance(PostDataD.data);
        var metaup = DB.NewMetaUnitParameter();
        var tableinfo = MetaDataUtilities.GetAllTables(metaup).Where(w => (w.MetaUID == id || w.MetaName == id)).FirstOrDefault();
        if (tableinfo == null)
        {
            return new
            {
                code = "failed",
                msg = "元数据不存在，无法继续进行操作"
            };
        }
        var columninfo = tableinfo.columns.Where(w => w.MetaColumnName == column_name).FirstOrDefault();
        if (columninfo == null)
        {
            return new
            {
                code = "failed",
                msg = "相关栏位资料不存在，无法继续进行操作"
            };
        }
        if (columninfo.MetaDataType != "auto-code")
        {
            return new
            {
                code = "failed",
                msg = "该栏位不是AutoCode类型栏位"
            };
        }
        var code = genAutoCode(metaup, tableinfo.MetaUID, columninfo.MetaColumnName, columninfo.MetaFormat, data);
        return new
        {
            code = "success",
            msg = "",
            data = code
        };
    }
    [EWRARouteDesc("获取下拉框或pop的内容")]
    [EWRARoute("patch", "/md_form/pop/{id}/{column_name}")]
    [EWRAAddInput("limit", "int", "每页笔数，当mode为Normal时需要提供", "默认为10", EFFC.Frame.Net.Base.Constants.RestInputPosition.QueryString, true)]
    [EWRAAddInput("page", "int", "指定页数，当mode为Normal时需要提供", "默认为1", EFFC.Frame.Net.Base.Constants.RestInputPosition.QueryString, true)]
    [EWRAAddInput("is_filter_deleted", "bool", "是否过滤掉逻辑删除的资料", "默认为true", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("id", "string", "元数据表的uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("column_name", "string", "指定栏位的名称", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("fixed_orderby_express", "string", "固定排序表达式，采用DBExpress的$orderby表达式写法，传入时采用base64+urlcode编码方式", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("filter", "string", "过滤条件", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("fixed_filter_express", "string", @"固定过滤条件表达式，采用DBExpress的$where表达式写法，传入时采用base64+urlcode编码方式；
表达式中的特殊条件如下：
$tree_in:单表数据结构条件查询，自动根据值及其子节点值查询符合条件的资料，的条件中的栏位必须为cadecase_tree、multi_cadecase_tree，并且引用表达式存在才生效，否则变为普通的$in操作，
$main_tree_in:主从表树数据结构条件查询，值结构与$in一样，自动根据值及其子节点值查询符合条件的资料，条件中的栏位必须为cadecase_main、multi_cadecase_main，并且引用表达式存在才生效，否则变为普通的$in操作
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("fixed_orderby_express", "string", "固定排序表达式，采用DBExpress的$orderby表达式写法，传入时采用base64+urlcode编码方式", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("other_condition_express", "string", @"其它查询条件表达式，采用DBExpress的$orderby表达式写法，传入时采用base64+urlcode编码方式,
注意:1.如果条件表达式中存在值为空的项目时，会自动过滤
2.如果表达式中的key与fixed_filter_express存在重复时，会自动覆盖fixed_filter_express中的条件表达式，所以如果同一个key在fixed_filter_express和other_condition_express中重复时，请将这两项手工合并到一处
表达式中的特殊条件如下：
$tree_in:单表数据结构条件查询，自动根据值及其子节点值查询符合条件的资料，的条件中的栏位必须为cadecase_tree、multi_cadecase_tree，并且引用表达式存在才生效，否则变为普通的$in操作
表达式中可以使用一些基础变量，如下：
界面上的参数用“@key@”来表示,
__login_id: 当前登录者ID,
__login_name: 当前登录者的登录名称
__user_no: 登录信息中的userno值,
__no: 登录信息中的no值,
__user_name: 登录信息中的username值,
__user_type: 登录信息中的usertype值,
__role_no: 当前登录者系统角色编号，多个,
__role_name: 当前登录者系统角色名称，多个,
__now: 当前时间，格式yyyy - MM - dd HH: mm:ss", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("this_data", "string", @"页面上当前编辑的行资料，先采用url编码，再采用base64编码，原数据格式:
{
    column_name1:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    column_name2:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    .....
    column_nameN:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
}", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("ref_data", "string", @"页面上当前编辑的行资料的父节点资料，先采用url编码，再采用base64编码，原数据格式:
{
    column_name1:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    column_name2:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    .....
    column_nameN:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
}", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"如果是授权无效的情况下，返回400错，其它情况的返回结果集（状态为200）如下：{
code:'success-成功，failed-失败',
msg:'提示信息',
column_value:'表示选中值的栏位名称,如果为空，则表示接受UI设定的任意值',
column_show:[{
    column_name:'栏位名称',
    column_desc:'栏位中文名称',
    ui_type:'UI控件类型'
}],
column_text:'表示选中值的对应的text',
total_count:'总笔数,pop才有',
page:'当前页数,pop才有',
total_page:'总页数,pop才有',
limit:'每页笔数,pop才有',
data:[结果集]")]
    object GetPop(string id, string column_name)
    {
        string fixed_filter_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_filter_express));
        string fixed_orderby_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_orderby_express));
        string other_condition_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.other_condition_express));
        var orderby_fixed_filter_express = FrameDLRObject.IsJsonThen(fixed_orderby_express, null, FrameDLRFlags.SensitiveCase);
        var is_filter_deleted = BoolStd.IsNotBoolThen(PostDataD.is_filter_deleted, true);
        string filter = ComFunc.nvl(PostDataD.filter);

        var where_fixed_filter_express = parseFixedExpress(fixed_filter_express);
        var where_other_condition_express = parseFixedExpress(other_condition_express);

        if (fixed_filter_express != "" && where_fixed_filter_express == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_filter_express格式不正确"
            };
        }
        if (fixed_orderby_express != "" && orderby_fixed_filter_express == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_orderby_express格式不正确"
            };
        }

        SetCacheEnable(false);
        var metaup = DB.NewMetaUnitParameter();
        var up = DB.NewDBUnitParameter();
        var tableinfo = MetaDataUtilities.GetAllTables(metaup).Where(w => (w.MetaUID == id || w.MetaName == id)).FirstOrDefault();
        if (tableinfo == null)
        {
            return new
            {
                code = "failed",
                msg = "元数据不存在，无法继续进行操作"
            };
        }
        var metainfo = tableinfo.columns.Where(w => w.MetaColumnName == column_name).FirstOrDefault();
        if (metainfo == null)
        {
            return new
            {
                code = "failed",
                msg = "相关栏位资料不存在，无法继续进行操作"
            };
        }
        var data_type = ComFunc.nvl(metainfo.MetaDataType);
        var column_ref = ComFunc.nvl(metainfo.MetaReference);
        if (column_ref == "")
        {
            return new
            {
                code = "failed",
                msg = "相关栏位缺少关联数据，无法继续进行操作"
            };
        }
        var refResult = ref_express.ParseExpress(column_ref);
        if (refResult == null)
        {
            return new
            {
                code = "failed",
                msg = "相关栏位关联信息描述存在错误，无法继续进行操作"
            };
        }
        var data_str = ComFunc.nvl(PostDataD.this_data).Replace(" ", "+");
        var this_data_base64str = ComFunc.IsBase64Then(data_str);
        string this_data_str = ComFunc.UrlDecode(this_data_base64str);
        var this_data = FrameDLRObject.IsJsonThen(this_data_str);
        if (data_str != "" && (this_data_str == "" || this_data == null))
        {
            return new
            {
                code = "failed",
                msg = "当前行资料格式不正确"
            };
        }
        var ref_data_str = ComFunc.nvl(PostDataD.ref_data).Replace(" ", "+");
        var ref_this_data_base64str = ComFunc.IsBase64Then(ref_data_str);
        string ref_this_data_str = ComFunc.UrlDecode(ref_this_data_base64str);
        var ref_data = FrameDLRObject.IsJsonThen(ref_this_data_str);
        if (ref_data_str != "" && (ref_this_data_str == "" || ref_data == null))
        {
            return new
            {
                code = "failed",
                msg = "父节点资料格式不正确"
            };
        }
        var data = new List<FrameDLRObject>();
        UnitDataCollection result = null;
        //树结构表达式条件过滤
        Func<string, string, bool, object, object[]> tree_func = (cur_table, column, is_parent_column, value) =>
        {
            return RefExpreeTreeIn(up, metaup, cur_table, column, value, is_parent_column);
        };
        var dbexpress = refResult.ToDBExpress(this_data, false, ref_data, false, tree_func, false, getOtherData());
        var tablename = refResult.TableName;
        var target = MetaDataUtilities.GetAllTables(metaup).Where(w => w.MetaName == tablename).FirstOrDefault();
        if (target == null)
        {
            return new
            {
                code = "failed",
                msg = "目标表不存在，无法继续进行操作"
            };
        }
        FrameDLRObject where = dbexpress.GetValue("$where") == null ? FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase) : (FrameDLRObject)dbexpress.GetValue("$where");
        //过滤逻辑删除的资料
        if (is_filter_deleted && !tablename.ToUpper().StartsWith("COMMON_"))
        {
            where.SetValue("_is_deleted", 0);
        }
        //输入查询条件
        if (filter != "")
        {
            var or = new List<FrameDLRObject>();
            foreach (var c in refResult.ShowColumns)
            {
                FrameDLRObject dobj = FrameDLRObject.CreateInstance();
                dobj.SetValue(c, FrameDLRObject.CreateInstanceFromat(@"{
'$like':{0}
}", filter));
                or.Add(dobj);

            }
            where.SetValue("$or", or);
        }
        //其它查询条件
        if (where_other_condition_express != null)
        {
            RemoveFilterEmptry(where_other_condition_express);
            foreach (var key in where_other_condition_express.Keys)
            {
                if (ComFunc.nvl(where_other_condition_express.GetValue(key)) != "")
                {
                    where.SetValue(key, where_other_condition_express.GetValue(key));
                }
            }
        }
        if (where_fixed_filter_express != null)
        {
            foreach (var key in where_fixed_filter_express.Keys)
            {
                if (ComFunc.nvl(where_fixed_filter_express.GetValue(key)) != "")
                {
                    where.SetValue(key, where_fixed_filter_express.GetValue(key));
                }
            }
        }
        //对特殊条件操作进行解析
        if (where.Items.Count > 0)
        {
            var tree_column = target.columns.Where(w => w.MetaDataType == "cadecase_tree" || w.MetaDataType == "multi_cadecase_tree").ToArray();
            var main_tree_column = target.columns.Where(w => w.MetaDataType == "cadecase_main" || w.MetaDataType == "multi_cadecase_main").ToArray();
            foreach (var item in where.Items)
            {
                if (item.Value is FrameDLRObject)
                {
                    var dobj = (FrameDLRObject)item.Value;
                    foreach (var k in dobj.Keys)
                    {
                        if (k == "$tree_in")
                        {
                            var c = tree_column.Where(w => w.MetaColumnName.ToLower() == item.Key.ToLower()).FirstOrDefault();
                            if (c == null)
                            {
                                var v = dobj.GetValue(k);
                                dobj.Remove(k);
                                dobj.SetValue("$in", v);
                                continue;
                            }

                            var newv = TreeIn(up, metaup, dobj.GetValue(k), c);
                            dobj.Remove(k);
                            dobj.SetValue("$in", newv);
                        }
                    }
                }
            }
        }

        if (where.Items.Count > 0)
        {
            dbexpress.SetValue("$where", where);
        }
        //order by
        FrameDLRObject orderby = orderby_fixed_filter_express == null ? FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase) : orderby_fixed_filter_express;
        orderby.SetValue("sort_no", "asc");
        dbexpress.SetValue("$orderby", orderby);

        if (data_type == "pop"
            || data_type == "multi-pop")
        {
            dbexpress.SetValue("sort_no", true);
            dbexpress.SetValue("$acttype", "QueryByPage");
        }
        result = DB.Excute(up, dbexpress, true);
        data = result.QueryData<FrameDLRObject>();

        //获取column_show的中文名称
        var metacolumns = target.columns;
        var column_map = metacolumns.ToDictionary(k => k.MetaColumnName, v => new { v.MetaColumnDesc, v.UI_TYPE });
        if (data_type == "pop"
           || data_type == "multi-pop")
        {
            #region 处理各个栏位的UI数据和关联项
            SetRefColumnsText(metaup, up, target, metacolumns, data, false);
            #endregion
            return new
            {
                code = "success",
                msg = "",
                column_value = refResult.KeyColumn,
                column_show = from t in refResult.ShowColumns
                              select new
                              {
                                  column_name = t,
                                  column_desc = column_map.ContainsKey(t) ? column_map[t].MetaColumnDesc : "",
                                  ui_type = column_map.ContainsKey(t) ? column_map[t].UI_TYPE : "Input"
                              },
                column_text = refResult.TextColumn,
                total_count = result.TotalRow,
                page = result.CurrentPage,
                total_page = result.TotalPage,
                limit = result.Count_Of_OnePage,
                data
            };
        }
        else
        {
            return new
            {
                code = "success",
                msg = "",
                column_value = refResult.KeyColumn,
                column_show = from t in refResult.ShowColumns
                              select new
                              {
                                  column_name = t,
                                  column_desc = column_map.ContainsKey(t) ? column_map[t].MetaColumnDesc : "",
                                  ui_type = column_map.ContainsKey(t) ? column_map[t].UI_TYPE : "Input"
                              },
                column_text = refResult.TextColumn,
                data
            };
        }
    }
    [EWRARouteDesc("根据给定的值获取树表级联下拉框的text")]
    [EWRARoute("post", "/md_form/pop/{id}/{column_name}/text")]
    [EWRAAddInput("id", "string", "元数据表的uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("column_name", "string", "指定栏位的名称", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("value", "string", "值，多选的用逗号分割", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("is_filter_deleted", "bool", "是否过滤掉逻辑删除的资料", "默认为true", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"如果是授权无效的情况下，返回400错，其它情况的返回结果集（状态为200）如下：{
code:'success-成功，failed-失败',
msg:'提示信息',
data:[{
code:'值',
text:'显示文本'
}]")]
    object GetPopText(string id, string column_name)
    {
        string value = ComFunc.nvl(PostDataD.value);
        var is_filter_deleted = BoolStd.IsNotBoolThen(PostDataD.is_filter_deleted, true);
        if (value == "")
        {
            return new
            {
                code = "success",
                msg = "",
                data = new List<object>()
            };
        }

        var metaup = DB.NewMetaUnitParameter();
        var up = DB.NewDBUnitParameter();
        var tableinfo = MetaDataUtilities.GetAllTables(metaup).Where(w => (w.MetaUID == id || w.MetaName == id)).FirstOrDefault();
        if (tableinfo == null)
        {
            return new
            {
                code = "failed",
                msg = "元数据不存在，无法继续进行操作"
            };
        }
        var metainfo = tableinfo.columns.Where(w => w.MetaColumnName == column_name).FirstOrDefault();
        if (metainfo == null)
        {
            return new
            {
                code = "failed",
                msg = "相关栏位资料不存在，无法继续进行操作"
            };
        }
        var data_type = ComFunc.nvl(metainfo.MetaDataType);
        var column_ref = ComFunc.nvl(metainfo.MetaReference);
        if (column_ref == "")
        {
            return new
            {
                code = "failed",
                msg = "相关栏位缺少关联数据，无法继续进行操作"
            };
        }
        var refResult = ref_express.ParseExpress(column_ref);
        if (refResult == null)
        {
            return new
            {
                code = "failed",
                msg = "相关栏位关联信息描述存在错误，无法继续进行操作"
            };
        }
        var column_value_key = ComFunc.nvl(refResult.KeyColumn);
        var column_text_key = ComFunc.nvl(refResult.TextColumn);
        List<FrameDLRObject> ref_list = new List<FrameDLRObject>();
        if (refResult.Filter.Count <= 0)
        {
            FrameDLRObject dbexpress = refResult.ToDBExpress(null, is_filter_deleted, null, false, null, true);
            dbexpress.SetValue(column_value_key, true);
            dbexpress.SetValue(column_text_key, true);
            FrameDLRObject where = dbexpress.GetValue("$where") == null ? FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase) : (FrameDLRObject)dbexpress.GetValue("$where");
            FrameDLRObject inw = FrameDLRObject.CreateInstance();
            inw.SetValue("$in", value.Split(","));
            where.SetValue(column_value_key, inw);
            dbexpress.SetValue("$where", where);
            ref_list = DB.Excute(up, dbexpress, true).QueryData<FrameDLRObject>();
        }
        var data = (from t in ref_list
                    select new
                    {
                        code = t.GetValue(column_value_key),
                        text = t.GetValue(column_text_key)
                    }).ToList();

        return new
        {
            code = "success",
            msg = "",
            data
        };
    }
    [EWRARouteDesc("获取下拉框或pop的内容-移动端使用")]
    [EWRARoute("post", "/md_form/pop/{id}/{column_name}")]
    [EWRAAddInput("limit", "int", "每页笔数，当mode为Normal时需要提供", "默认为10", EFFC.Frame.Net.Base.Constants.RestInputPosition.QueryString, true)]
    [EWRAAddInput("page", "int", "指定页数，当mode为Normal时需要提供", "默认为1", EFFC.Frame.Net.Base.Constants.RestInputPosition.QueryString, true)]
    [EWRAAddInput("is_filter_deleted", "bool", "是否过滤掉逻辑删除的资料", "默认为true", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("id", "string", "元数据表的uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("column_name", "string", "指定栏位的名称", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("fixed_orderby_express", "string", "固定排序表达式，采用DBExpress的$orderby表达式写法，传入时采用base64+urlcode编码方式", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("filter", "string", "过滤条件", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("this_data", "string", @"页面上当前编辑的行资料，先采用url编码，再采用base64编码，原数据格式:
{
    column_name1:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    column_name2:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    .....
    column_nameN:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
}", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("ref_data", "string", @"页面上当前编辑的行资料的父节点资料，先采用url编码，再采用base64编码，原数据格式:
{
    column_name1:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    column_name2:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    .....
    column_nameN:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
}", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"如果是授权无效的情况下，返回400错，其它情况的返回结果集（状态为200）如下：{
code:'success-成功，failed-失败',
msg:'提示信息',
column_value:'表示选中值的栏位名称,如果为空，则表示接受UI设定的任意值',
column_show:[{
    column_name:'栏位名称',
    column_desc:'栏位中文名称',
    ui_type:'UI控件类型'
}],
column_text:'表示选中值的对应的text',
total_count:'总笔数,pop才有',
page:'当前页数,pop才有',
total_page:'总页数,pop才有',
limit:'每页笔数,pop才有',
data:[结果集]")]
    object GetPop4Mobile(string id, string column_name)
    {
        return GetPop(id, column_name);
    }
    [EWRARouteDesc("获取ui_type为picxy的弹出框内容")]
    [EWRARoute("patch", "/md_form/pop/picxy/{id}/{column_name}")]
    [EWRAAddInput("id", "string", "元数据表的uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("column_name", "string", "指定栏位的名称", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("is_filter_deleted", "bool", "是否过滤掉逻辑删除的资料", "默认为true", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("this_data", "string", @"页面上当前编辑的行资料，先采用url编码，再采用base64编码，原数据格式:
{
    column_name1:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    column_name2:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    .....
    column_nameN:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
}", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, true)]
    [EWRAAddInput("ref_data", "string", @"页面上当前编辑的行资料的父节点资料，先采用url编码，再采用base64编码，原数据格式:
{
    column_name1:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    column_name2:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    .....
    column_nameN:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
}", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"如果是授权无效的情况下，返回400错，其它情况的返回结果集（状态为200）如下：{
code:'success-成功，failed-失败',
msg:'提示信息',
filetype:'文件的content-type类型'
filename:'文件名称',
filelength:'文件长度',
file:'文件内容，采用base64加密'
}")]
    object GetPicXYPop(string id, string column_name)
    {
        var is_filter_deleted = BoolStd.IsNotBoolThen(PostDataD.is_filter_deleted, true);

        SetCacheEnable(false);
        var metaup = DB.NewMetaUnitParameter();
        var up = DB.NewDBUnitParameter();
        var tableinfo = MetaDataUtilities.GetAllTables(metaup).Where(w => (w.MetaUID == id || w.MetaName == id)).FirstOrDefault();
        if (tableinfo == null)
        {
            return new
            {
                code = "failed",
                msg = "元数据不存在，无法继续进行操作"
            };
        }
        var metainfo = tableinfo.columns.Where(w => w.MetaColumnName == column_name && !w.IsVirsual).FirstOrDefault();
        if (metainfo == null)
        {
            return new
            {
                code = "failed",
                msg = "相关栏位资料不存在，无法继续进行操作"
            };
        }
        var column_ref = ComFunc.nvl(metainfo.MetaReference);
        if (column_ref == "")
        {
            return new
            {
                code = "failed",
                msg = "相关栏位缺少关联数据，无法继续进行操作"
            };
        }

        var refResult = ref_express.ParseExpress(column_ref);
        if (refResult == null)
        {
            return new
            {
                code = "failed",
                msg = "相关栏位关联信息描述存在错误，无法继续进行操作"
            };
        }
        var data_str = ComFunc.nvl(PostDataD.this_data).Replace(" ", "+");
        var this_data_base64str = ComFunc.IsBase64Then(data_str);
        string this_data_str = ComFunc.UrlDecode(this_data_base64str);
        var this_data = FrameDLRObject.IsJsonThen(this_data_str);
        if (data_str != "" && (this_data_str == "" || this_data == null))
        {
            return new
            {
                code = "failed",
                msg = "当前行资料格式不正确"
            };
        }
        var ref_data_str = ComFunc.nvl(PostDataD.ref_data).Replace(" ", "+");
        var ref_this_data_base64str = ComFunc.IsBase64Then(ref_data_str);
        string ref_this_data_str = ComFunc.UrlDecode(ref_this_data_base64str);
        var ref_data = FrameDLRObject.IsJsonThen(ref_this_data_str);
        if (ref_data_str != "" && (ref_this_data_str == "" || ref_data == null))
        {
            return new
            {
                code = "failed",
                msg = "父节点资料格式不正确"
            };
        }
        var dbexpress = refResult.ToDBExpress(this_data, false, ref_data, false, null, false, getOtherData());
        var tablename = ComFunc.nvl(dbexpress.GetValue("$table"));
        //过滤逻辑删除的资料
        if (is_filter_deleted && !tablename.ToUpper().StartsWith("COMMON_"))
        {
            FrameDLRObject where = dbexpress.GetValue("$where") == null ? FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase) : (FrameDLRObject)dbexpress.GetValue("$where");
            where.SetValue("_is_deleted", 0);
        }
        var data = DB.Excute(up, dbexpress, true);
        if (data.QueryTable.RowLength <= 0)
        {
            return new
            {
                code = "failed",
                msg = "无法查到指定图片数据"
            };
        }
        //只抓取第一行资料的第一个栏位的值
        var result = FileHelper.DoDownLoad(ComFunc.nvl(data.QueryTable[0, 0]));
        return result;
    }
    [EWRARouteDesc("获取ui_type为picxy的弹出框内容")]
    [EWRARoute("post", "/md_form/pop/picxy/{id}/{column_name}")]
    [EWRAAddInput("id", "string", "元数据表的uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("column_name", "string", "指定栏位的名称", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("is_filter_deleted", "bool", "是否过滤掉逻辑删除的资料", "默认为true", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("this_data", "string", @"页面上当前编辑的行资料，先采用url编码，再采用base64编码，原数据格式:
{
    column_name1:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    column_name2:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    .....
    column_nameN:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
}", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, true)]
    [EWRAAddInput("ref_data", "string", @"页面上当前编辑的行资料的父节点资料，先采用url编码，再采用base64编码，原数据格式:
{
    column_name1:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    column_name2:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    .....
    column_nameN:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
}", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"如果是授权无效的情况下，返回400错，其它情况的返回结果集（状态为200）如下：{
code:'success-成功，failed-失败',
msg:'提示信息',
filetype:'文件的content-type类型'
filename:'文件名称',
filelength:'文件长度',
file:'文件内容，采用base64加密'
}")]
    object GetPicXYPop4Mobile(string id, string column_name)
    {
        return GetPicXYPop(id, column_name);
    }
    [EWRARouteDesc("获取主从表级联下拉框的内容，逐级获取")]
    [EWRARoute("post", "/md_form/cadecase_ms/{id}/{column_name}")]
    [EWRAAddInput("id", "string", "元数据表的uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("column_name", "string", "指定栏位的名称", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("is_filter_deleted", "bool", "是否过滤掉逻辑删除的资料", "默认为true", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("parent_pk", "string", "上一级资料的PK", "为空时则表示拉出一级列表", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("parent_level", "int", "上一级资料的层级，从0开始", "为空时默认为0，表示拉出一级列表", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("start_meta_name", "string", "起始元数据表名，为空时表示从最顶层开始。比如一种5层结构：小区->片区->楼栋->单元->房屋，期望从楼栋开始选择，则该参数设定为楼栋的表名-Building即可", "默认为空", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, true)]
    [EWRAAddInput("start_level_column", "string", "起始层的栏位名称，parent_pk为空且start_level_column和start_level_value都有值才会生效", "默认为空", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, true)]
    [EWRAAddInput("start_level_value", "string", "起始层的栏位值，多个用逗号分隔，parent_pk为空且start_level_column和start_level_value都有值才会生效", "默认为空", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, true)]
    [EWRAOutputDesc("返回结果", @"如果是授权无效的情况下，返回400错，其它情况的返回结果集（状态为200）如下：{
code:'success-成功，failed-失败',
msg:'提示信息',
is_last_level:'表示是否为最后一级'
data:[{
code:'值',
text:'显示文本',
can_select:'表示该值是否允许被选，级联是需要选到目标资料集中的数据，而不是选择中间数据'
}]")]
    object GetCadecaseSelectMS(string id, string column_name)
    {
        string start_level_column = ComFunc.nvl(PostDataD.start_level_column);
        string start_level_value = ComFunc.nvl(PostDataD.start_level_value);
        var is_filter_deleted = BoolStd.IsNotBoolThen(PostDataD.is_filter_deleted, true);
        string parent_pk = ComFunc.nvl(PostDataD.parent_pk);
        int parent_level = IntStd.IsNotIntThen(PostDataD.parent_level, 0);
        string start_meta_name = ComFunc.nvl(PostDataD.start_meta_name);
        if (parent_pk == "") parent_level = 0;


        SetCacheEnable(false);
        var metaup = DB.NewMetaUnitParameter();
        var up = DB.NewDBUnitParameter();
        var tinfo = MetaDataUtilities.GetAllTables(metaup).Where(w => (w.MetaUID == id || w.MetaName == id)).FirstOrDefault();
        if (tinfo == null)
        {
            return new
            {
                code = "failed",
                msg = "元数据不存在，无法继续进行操作"
            };
        }
        var metainfo = tinfo.columns.Where(w => w.MetaColumnName == column_name && !w.IsVirsual).FirstOrDefault();
        if (metainfo == null)
        {
            return new
            {
                code = "failed",
                msg = "相关栏位资料不存在，无法继续进行操作"
            };
        }
        var data_type = ComFunc.nvl(metainfo.MetaDataType);
        var column_ref = ComFunc.nvl(metainfo.MetaReference);
        if (column_ref == "")
        {
            return new
            {
                code = "failed",
                msg = "相关栏位缺少关联数据，无法继续进行操作"
            };
        }

        var refResult = ref_express.ParseExpress(column_ref);
        if (refResult == null)
        {
            return new
            {
                code = "failed",
                msg = "相关栏位关联信息描述存在错误，无法继续进行操作"
            };
        }
        var data = new List<FrameDLRObject>();
        //根据ref表达式抓取定位table的名称
        var dbexpress = refResult.ToDBExpress(null);
        var tablename = refResult.TableName;
        var needed_tree_tables = BuildCadecaseMS_MetaTreeInfo(metaup, tablename);
        var start_table_info = needed_tree_tables.Where(w => w.TreeLevel == 1).FirstOrDefault();
        if (start_meta_name != "")
        {
            start_table_info = needed_tree_tables.Where(w => w.MetaName == start_meta_name).FirstOrDefault();
        }
        if (start_table_info == null)
        {
            return new
            {
                code = "failed",
                msg = "未找到起始元数据表资料"
            };
        }
        //计算parent_level真实level
        parent_level = IntStd.IsNotIntThen(start_table_info.TreeLevel, 1) - 1 + parent_level;
        var tableinfo = needed_tree_tables.Where(w => w.TreeLevel == parent_level + 1).FirstOrDefault();
        if (tableinfo == null) return new
        {
            code = "failed",
            msg = "未找到指定层级元数据表"
        };
        var table = ComFunc.nvl(tableinfo.MetaName);
        //showcolumn需要从下级表中抓取，如果table==refResult.TableName时，则showcolumn为refResult.TextColumn
        string show_column = "_default_pk";
        string key_column = "_default_pk";
        if (table == refResult.TableName)
        {
            key_column = refResult.KeyColumn;
            if (!string.IsNullOrEmpty(refResult.TextColumn))
                show_column = refResult.TextColumn;
        }
        else
        {
            var nexttableinfo = needed_tree_tables.Where(w => w.TreeLevel == parent_level + 2).FirstOrDefault();
            if (nexttableinfo != null)
            {
                if (ComFunc.nvl(nexttableinfo.MetaMainShowColumn) != "")
                    show_column = ComFunc.nvl(nexttableinfo.MetaMainShowColumn);
            }
        }
        data = (from t in DB.LamdaTable(up, table, "a")
                where t.notnull(parent_pk, t._default_ref == parent_pk)
                && t.iftrue(parent_pk == "" && start_level_column != "" && start_level_value != "", t.column(start_level_column).within(start_level_value))
                && t.iftrue(is_filter_deleted, t._is_deleted == 0)
                orderby t.sort_no, t.column(show_column)
                select new
                {
                    code = t.column(key_column),
                    text = t.column(show_column)
                }).GetQueryList(up).Select(d =>
                {
                    if (show_column == "_default_pk")
                        d.text = $"{d.code}(此处未设定显示栏位;1.设定主从表关系时，需要设定主表的显示栏位;2.请在元数据结构维护中，设定关联关系中的[关联展示字段])";
                    return d;
                }).ToList();
        foreach (dynamic item in data)
        {
            item.can_select = table == tablename;
        }

        return new
        {
            code = "success",
            msg = "",
            is_last_level = table == tablename,
            data
        };
    }
    [EWRARouteDesc("根据给定的值获取主从表级联下拉框的text")]
    [EWRARoute("post", "/md_form/cadecase_ms/{id}/{column_name}/text")]
    [EWRAAddInput("id", "string", "元数据表的uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("column_name", "string", "指定栏位的名称", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("value", "string", "值，多选的用逗号分割", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("is_filter_deleted", "bool", "是否过滤掉逻辑删除的资料", "默认为true", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"如果是授权无效的情况下，返回400错，其它情况的返回结果集（状态为200）如下：{
code:'success-成功，failed-失败',
msg:'提示信息',
data:[{
code:'值',
text:'显示文本'
}]")]
    object GetCadecaseSelectMSText(string id, string column_name)
    {
        var is_filter_deleted = BoolStd.IsNotBoolThen(PostDataD.is_filter_deleted, true);
        string value = ComFunc.nvl(PostDataD.value);
        if (value == "")
        {
            return new
            {
                code = "success",
                msg = "",
                data = new List<object>()
            };
        }

        var metaup = DB.NewMetaUnitParameter();
        var up = DB.NewDBUnitParameter();
        var tinfo = MetaDataUtilities.GetAllTables(metaup).Where(w => (w.MetaUID == id || w.MetaName == id)).FirstOrDefault();
        if (tinfo == null)
        {
            return new
            {
                code = "failed",
                msg = "元数据不存在，无法继续进行操作"
            };
        }
        var metainfo = tinfo.columns.Where(w => w.MetaColumnName == column_name && !w.IsVirsual).FirstOrDefault();
        if (metainfo == null)
        {
            return new
            {
                code = "failed",
                msg = "相关栏位资料不存在，无法继续进行操作"
            };
        }
        var data_type = ComFunc.nvl(metainfo.MetaDataType);
        var column_ref = ComFunc.nvl(metainfo.MetaReference);
        if (column_ref == "")
        {
            return new
            {
                code = "failed",
                msg = "相关栏位缺少关联数据，无法继续进行操作"
            };
        }

        var refResult = ref_express.ParseExpress(column_ref);
        if (refResult == null)
        {
            return new
            {
                code = "failed",
                msg = "相关栏位关联信息描述存在错误，无法继续进行操作"
            };
        }

        //搜索元数据表级联结构
        var needed_table_list = BuildCadecaseMS_MetaTreeInfo(metaup, refResult.TableName);
        if (needed_table_list.Count <= 0)
        {
            return new
            {
                code = "success",
                msg = "",
                data = (from code in value.Split(',')
                        select new
                        {
                            code,
                            text = ""
                        }).ToList()
            };
        }
        var column_value_key = ComFunc.nvl(refResult.KeyColumn);
        var column_text_key = ComFunc.nvl(refResult.TextColumn);

        var column_show_key = from t in refResult.ShowColumns
                              select new
                              {
                                  column_name = t
                              };
        if (column_text_key == "") column_text_key = "_default_pk";
        var pks = value.Split(",");

        var ref_list = (from t in DB.LamdaTable(up, refResult.TableName, "a")
                        where t.iftrue(is_filter_deleted, t._is_deleted == 0) && t.column(refResult.KeyColumn).within(string.Join(",", pks))
                        select new
                        {
                            code = t.column(refResult.KeyColumn),
                            text = t.column(column_text_key),
                            t._default_pk,
                            ref_pk = t._default_ref,
                            next_ref_pk = t._default_ref
                        }).GetQueryList(up);//.ToDictionary(k => k.GetValue("code"), val => val.GetValue("text"));
                                            //逆向递归，找出级联层级，使text显示层级
        var curtableinfo = needed_table_list.Where(w => w.MetaName == refResult.TableName).FirstOrDefault();
        if (curtableinfo == null) return new
        {
            code = "success",
            msg = "",
            data = (from code in value.Split(',')
                    select new
                    {
                        code,
                        text = ""
                    }).ToList()
        };
        var level = IntStd.IsNotIntThen(curtableinfo.TreeLevel);
        var meta_show_column = ComFunc.nvl(curtableinfo.MetaMainShowColumn);
        for (var i = level - 1; i > 0; i--)
        {
            var ti = needed_table_list.Where(w => w.TreeLevel == i).FirstOrDefault();
            if (ti == null) continue;
            var tn = ComFunc.nvl(ti.MetaName);
            var tpks = ref_list.Select(d => ComFunc.nvl(d.GetValue("next_ref_pk")));
            var tdic = (from t in DB.LamdaTable(up, tn, "a")
                        where t._default_pk.within(string.Join(",", tpks))
                        select new
                        {
                            code = t._default_pk,
                            text = t.column(meta_show_column),
                            ref_pk = t._default_ref,
                            next_ref_pk = t._default_ref
                        }).GetQueryList(up).ToDictionary(k => ComFunc.nvl(k.GetValue("code")), v => v);
            foreach (dynamic item in ref_list)
            {
                var tkey = ComFunc.nvl(item.next_ref_pk);
                if (tkey == "") continue;
                var tpretext = tdic.ContainsKey(tkey) ? ComFunc.nvl(tdic[tkey].GetValue("text")) : "";
                var tnext_ref_pk = tdic.ContainsKey(tkey) ? ComFunc.nvl(tdic[tkey].GetValue("next_ref_pk")) : "";
                if (tpretext == "") tpretext = "--";
                if (tdic.ContainsKey(tkey))
                {
                    item.text = $"{tpretext}/{item.text}";
                }
                item.next_ref_pk = tnext_ref_pk;
            }
            meta_show_column = ComFunc.nvl(ti.MetaMainShowColumn);
        }

        var textlist = (from t in ref_list
                        select new
                        {
                            code = ComFunc.nvl(t.GetValue("code")),
                            text = ComFunc.nvl(t.GetValue("text"))
                        }).ToList();

        return new
        {
            code = "success",
            msg = "",
            data = textlist
        };
    }
    [EWRARouteDesc("获取单表级联下拉框的内容，逐级获取")]
    [EWRARoute("post", "/md_form/cadecase_tree/{id}/{column_name}")]
    [EWRAAddInput("is_filter_deleted", "bool", "是否过滤掉逻辑删除的资料", "默认为true", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("id", "string", "元数据表的uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("column_name", "string", "指定栏位的名称", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("parent_pk", "string", "上一级资料的PK", "为空时则表示拉出一级列表", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("parent_level", "int", "上一级资料的层级，从0开始", "为空时默认为0，表示拉出一级列表", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("start_level_column", "string", "起始层的栏位名称，parent_pk为空且start_level_column和start_level_value都有值才会生效", "默认为空", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, true)]
    [EWRAAddInput("start_level_value", "string", "起始层的栏位值，多个用逗号分隔,parent_pk为空且start_level_column和start_level_value都有值才会生效", "默认为空", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, true)]
    [EWRAAddInput("fixed_orderby_express", "string", "固定排序表达式，采用DBExpress的$orderby表达式写法，传入时采用base64+urlcode编码方式", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("this_data", "string", @"页面上当前编辑的行资料，先采用url编码，再采用base64编码，原数据格式:
{
    column_name1:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    column_name2:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    .....
    column_nameN:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
}", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("ref_data", "string", @"页面上当前编辑的行资料的父节点资料，先采用url编码，再采用base64编码，原数据格式:
{
    column_name1:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    column_name2:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
    .....
    column_nameN:'值，如果为file、picture类型则值的格式内容为上传后的文件路径',
}", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"如果是授权无效的情况下，返回400错，其它情况的返回结果集（状态为200）如下：{
code:'success-成功，failed-失败',
msg:'提示信息',
data:[{
code:'值',
text:'显示文本'
}]")]
    object GetCadeCaseTree(string id, string column_name)
    {
        string start_level_column = ComFunc.nvl(PostDataD.start_level_column);
        string start_level_value = ComFunc.nvl(PostDataD.start_level_value);
        string fixed_orderby_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_orderby_express));
        var orderby_fixed_filter_express = FrameDLRObject.IsJsonThen(fixed_orderby_express, null, FrameDLRFlags.SensitiveCase);
        var is_filter_deleted = BoolStd.IsNotBoolThen(PostDataD.is_filter_deleted, true);
        string parent_pk = ComFunc.nvl(PostDataD.parent_pk);
        int parent_level = IntStd.IsNotIntThen(PostDataD.parent_level, 1);
        if (parent_pk == "") parent_level = 0;

        SetCacheEnable(false);
        var metaup = DB.NewMetaUnitParameter();
        var up = DB.NewDBUnitParameter();
        var tinfo = MetaDataUtilities.GetAllTables(metaup).Where(w => (w.MetaUID == id || w.MetaName == id)).FirstOrDefault();
        if (tinfo == null)
        {
            return new
            {
                code = "failed",
                msg = "元数据不存在，无法继续进行操作"
            };
        }
        var metainfo = tinfo.columns.Where(w => w.MetaColumnName == column_name && !w.IsVirsual).FirstOrDefault();
        if (metainfo == null)
        {
            return new
            {
                code = "failed",
                msg = "相关栏位资料不存在，无法继续进行操作"
            };
        }
        var data_type = ComFunc.nvl(metainfo.MetaDataType);
        var column_ref = ComFunc.nvl(metainfo.MetaReference);
        if (column_ref == "")
        {
            return new
            {
                code = "failed",
                msg = "相关栏位缺少关联数据，无法继续进行操作"
            };
        }

        var refResult = ref_express.ParseExpress(column_ref);
        if (refResult == null)
        {
            return new
            {
                code = "failed",
                msg = "相关栏位关联信息描述存在错误，无法继续进行操作"
            };
        }
        var column_value_key = ComFunc.nvl(refResult.KeyColumn);

        var data_str = ComFunc.nvl(PostDataD.this_data).Replace(" ", "+");
        var this_data_base64str = ComFunc.IsBase64Then(data_str);
        string this_data_str = ComFunc.UrlDecode(this_data_base64str);
        var this_data = FrameDLRObject.IsJsonThen(this_data_str);
        if (data_str != "" && (this_data_str == "" || this_data == null))
        {
            return new
            {
                code = "failed",
                msg = "当前行资料格式不正确"
            };
        }
        var ref_data_str = ComFunc.nvl(PostDataD.ref_data).Replace(" ", "+");
        var ref_this_data_base64str = ComFunc.IsBase64Then(ref_data_str);
        string ref_this_data_str = ComFunc.UrlDecode(ref_this_data_base64str);
        var ref_data = FrameDLRObject.IsJsonThen(ref_this_data_str);
        if (ref_data_str != "" && (ref_this_data_str == "" || ref_data == null))
        {
            return new
            {
                code = "failed",
                msg = "父节点资料格式不正确"
            };
        }
        //获取元数据表定义的资料
        var tablename = refResult.TableName;

        var tablelist = MetaDataUtilities.GetAllTables(metaup).Where(w => w.MetaName == tablename && w.IsCreated).ToList();
        var tableinfo = tablelist.Where(w => w.MetaName == tablename).FirstOrDefault();
        if (tableinfo == null)
        {
            return new
            {
                code = "failed",
                msg = "关联表不存在或未创建"
            };
        }
        var is_dic = tableinfo.IsDic;



        var data = new List<FrameDLRObject>();
        UnitDataCollection result = null;
        var dbexpress = refResult.ToDBExpress(this_data, false, ref_data);

        FrameDLRObject where = (parent_pk != "" || dbexpress.GetValue("$where") == null) ? FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase) : (FrameDLRObject)dbexpress.GetValue("$where");
        var parenet_uid = "";



        if (!is_dic)
        {
            if (column_value_key == "") column_value_key = "_default_pk";
            //获取起始层级
            if (column_value_key == "_default_pk")
            {
                parenet_uid = parent_pk;
            }
            else
            {
                dynamic parentinfo = (from t in DB.LamdaTable(up, tablename, "a")
                                      where t.column(column_value_key) == parent_pk
                                      select t).GetQueryList(up).FirstOrDefault();
                if (parentinfo != null)
                {
                    parenet_uid = parentinfo._default_pk;
                }
            }

            dbexpress.SetValue("_default_pk", true);
            where.SetValue("#isnull(_default_parent_pk,)", parenet_uid);
        }
        else
        {
            if (column_value_key == "") column_value_key = "code";
            if (column_value_key == "code")
            {
                parenet_uid = parent_pk;
            }
            else
            {
                dynamic parentinfo = (from t in DB.LamdaTable(up, tablename, "a")
                                      where t.column(column_value_key) == parent_pk
                                      select t).GetQueryList(up).FirstOrDefault();
                if (parentinfo != null)
                {
                    parenet_uid = parentinfo.code;
                }
            }

            dbexpress.SetValue("code", true);
            where.SetValue("p_code", parenet_uid);
        }
        //过滤一级列表
        if (parenet_uid == "" && start_level_column != "" && start_level_value != "")
        {
            where.SetValue(start_level_column, FrameDLRObject.CreateInstanceFromat(@"{
'$in':{0}
}", start_level_value.Split(",")));
        }
        //过滤逻辑删除的资料
        if (is_filter_deleted && !is_dic)
        {
            where.SetValue("_is_deleted", 0);
        }
        dbexpress.SetValue("$where", where);
        //order by
        FrameDLRObject orderby = orderby_fixed_filter_express == null ? FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase) : orderby_fixed_filter_express;
        orderby.SetValue("sort_no", "asc");
        dbexpress.SetValue("$orderby", orderby);

        result = DB.Excute(up, dbexpress, true);
        data = result.QueryData<FrameDLRObject>().Select(d =>
        {
            FrameDLRObject dobj = FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase);
            dobj.SetValue("code", ComFunc.nvl(d.GetValue(column_value_key)));
            if (string.IsNullOrEmpty(refResult.TextColumn))
            {
                dobj.SetValue("text", $"{dobj.GetValue("code")}(请在元数据结构维护中，设定关联关系中的[关联展示字段])");
            }
            else
            {
                dobj.SetValue("text", d.GetValue(refResult.TextColumn));
            }


            return dobj;
        }).ToList();


        return new
        {
            code = "success",
            msg = "",
            data
        };

    }
    [EWRARouteDesc("根据给定的值获取树表级联下拉框的text")]
    [EWRARoute("post", "/md_form/cadecase_tree/{id}/{column_name}/text")]
    [EWRAAddInput("id", "string", "元数据表的uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("column_name", "string", "指定栏位的名称", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("value", "string", "值，多选的用逗号分割", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("is_filter_deleted", "bool", "是否过滤掉逻辑删除的资料", "默认为true", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"如果是授权无效的情况下，返回400错，其它情况的返回结果集（状态为200）如下：{
code:'success-成功，failed-失败',
msg:'提示信息',
data:[{
code:'值',
text:'显示文本'
}]")]
    object GetCadecaseSelectTressText(string id, string column_name)
    {
        var is_filter_deleted = BoolStd.IsNotBoolThen(PostDataD.is_filter_deleted, true);
        string value = ComFunc.nvl(PostDataD.value);
        if (value == "")
        {
            return new
            {
                code = "success",
                msg = "",
                data = new List<object>()
            };
        }

        var metaup = DB.NewMetaUnitParameter();
        var up = DB.NewDBUnitParameter();
        var tinfo = MetaDataUtilities.GetAllTables(metaup).Where(w => (w.MetaUID == id || w.MetaName == id)).FirstOrDefault();
        if (tinfo == null)
        {
            return new
            {
                code = "failed",
                msg = "元数据不存在，无法继续进行操作"
            };
        }
        var metainfo = tinfo.columns.Where(w => w.MetaColumnName == column_name && !w.IsVirsual).FirstOrDefault();
        if (metainfo == null)
        {
            return new
            {
                code = "failed",
                msg = "相关栏位资料不存在，无法继续进行操作"
            };
        }
        var data_type = ComFunc.nvl(metainfo.MetaDataType);
        var column_ref = ComFunc.nvl(metainfo.MetaReference);
        if (column_ref == "")
        {
            return new
            {
                code = "failed",
                msg = "相关栏位缺少关联数据，无法继续进行操作"
            };
        }

        var refResult = ref_express.ParseExpress(column_ref);
        if (refResult == null)
        {
            return new
            {
                code = "failed",
                msg = "相关栏位关联信息描述存在错误，无法继续进行操作"
            };
        }
        var reftableinfo = MetaDataUtilities.GetAllTables(metaup).Where(w => w.MetaName == refResult.TableName).FirstOrDefault();
        var column_text_key = ComFunc.nvl(refResult.TextColumn);
        var column_value_key = ComFunc.nvl(refResult.KeyColumn);
        var column_p_pk_key = "_default_parent_pk";
        var column_pk_key = "_default_pk";
        if (reftableinfo.IsDic)
        {
            column_pk_key = "code";
            column_p_pk_key = "p_code";
        }
        else
        {
            column_pk_key = "_default_pk";
            column_p_pk_key = "_default_parent_pk";
        }
        var ref_dic = new Dictionary<dynamic, dynamic>();
        FrameDLRObject dbexpress = refResult.ToDBExpress(null, is_filter_deleted, null, false, null, true);
        dbexpress.SetValue(column_p_pk_key, true);
        dbexpress.SetValue(column_pk_key, true);
        var ref_list = DB.Excute(up, dbexpress, true).QueryData<FrameDLRObject>().Select(d =>
        {
            d.next_ref_pk = ((FrameDLRObject)d).GetValue(column_p_pk_key);
            d.text = ((FrameDLRObject)d).GetValue(column_text_key);
            return d;
        }).ToList();



        var is_continue = true;
        do
        {
            is_continue = false;
            var tpks = ref_list.Select(d => ComFunc.nvl(d.GetValue("next_ref_pk"))).ToArray();
            var t_dic = (from t in DB.LamdaTable(up, refResult.TableName, "a")
                         where t.column(column_pk_key).within(string.Join(",", tpks))
                         select new
                         {
                             v = t.column(column_value_key),
                             pk = t.column(column_pk_key),
                             text = t.column(column_text_key),
                             p_pk = t.column(column_p_pk_key)
                         }).GetQueryList(up).ToDictionary(k => k.GetValue("pk"), v => v);
            foreach (dynamic item in ref_list)
            {
                var p_pk = ComFunc.nvl(item.next_ref_pk);
                if (p_pk != "")
                {
                    is_continue = is_continue || true;
                }
                else
                {
                    is_continue = is_continue || false;
                    continue;
                }
                var tpretext = t_dic.ContainsKey(p_pk) ? ComFunc.nvl(t_dic[p_pk].GetValue("text")) : "";
                var tnext_ref_pk = t_dic.ContainsKey(p_pk) ? ComFunc.nvl(t_dic[p_pk].GetValue("p_pk")) : "";
                if (tpretext == "") tpretext = "--";
                if (t_dic.ContainsKey(p_pk))
                {
                    item.text = $"{tpretext}/{item.text}";
                }
                item.next_ref_pk = tnext_ref_pk;
            }
        } while (is_continue);
        var arr = value.Split(",");
        var textlist = (from t in ref_list
                        where arr.Contains(ComFunc.nvl(t.GetValue(column_value_key)))
                        select new
                        {
                            code = ComFunc.nvl(t.GetValue(column_value_key)),
                            text = ComFunc.nvl(t.GetValue("text"))
                        }).ToList();
        return new
        {
            code = "success",
            msg = "",
            data = textlist
        };
    }
    #endregion

    #region LocalFunction
    /// <summary>
    /// 获取otherdata，全局参量
    /// </summary>
    /// <param name="json"></param>
    /// <returns></returns>
    FrameDLRObject getOtherData()
    {
        FrameDLRObject rtn = FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase);
        rtn.SetValue("__now", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
        rtn.SetValue("__login_id", TokenPayLoad.ID);
        rtn.SetValue("__login_name", TokenPayLoad["name"]);
        rtn.SetValue("__user_no", TokenPayLoad["userno"]);
        rtn.SetValue("__user_name", TokenPayLoad["username"]);
        rtn.SetValue("__user_type", TokenPayLoad["usertype"]);
        rtn.SetValue("__role_no", TokenPayLoad["roleno"]);
        rtn.SetValue("__role_name", TokenPayLoad["rolename"]);
        rtn.SetValue("__login_uid", TokenPayLoad["login_uid"]);

        return rtn;
    }
    #endregion


}
}
